package com.yuyou.tas.gateway.filter;

import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;

import com.netflix.zuul.ZuulFilter;
import com.netflix.zuul.context.RequestContext;

public class CORSFilter extends ZuulFilter{

	
	@Autowired
	private StringRedisTemplate stringRedisTemplate;
	
	@Override
	public Object run() {
		RequestContext ctx = RequestContext.getCurrentContext() ;
		HttpServletResponse response =ctx.getResponse();
        response.setHeader("Access-Control-Allow-Origin", "*");
        response.setHeader("Access-Control-Allow-Methods", "POST, GET, OPTIONS, DELETE");
        response.setHeader("Access-Control-Max-Age", "3600");
        response.addHeader("Access-Control-Allow-Headers", "Access-Control-Allow-Headers,If-Modified-Since, Origin,Accept, X-Requested-With, Content-Type, Access-Control-Request-Method, Access-Control-Request-Headers,accessToken"); 
        return null;
	}
	
	@Override
	public boolean shouldFilter() {
		return false;
	}

	@Override
	public int filterOrder() {
		return 0;
	}

	@Override
	public String filterType() {
		 return "post";
	}

}
